<?php
class retrieve_users extends retrieve_base{

	private $module_display_options 	= array();
	function create_client_details($parameters){
		$client_identifier = $this->check_parameters($parameters,"client_identifier",-1);
		/**
		* insert available_fields data
		*/
		//		$length_array = count($data);
//		$length_array=0;
//		for ($index=0; $length_array > $index;$index++){
//			$this->db->query($data[$index]);
//		}

	}
	/**
	* This function is used to return the list of orders to be dealt with
	*/
	function getDigitalDesktop($parameters){
		if (($this->parent->server[LICENCE_TYPE]==ECMS)||($this->parent->server[LICENCE_TYPE]==MECM)){
			$grp_info = $this->check_parameters($_SESSION,"SESSION_GROUP",Array());
			$max_grps = count($grp_info);
			$access_list = "";
			$access_array = array();
			$ALL=0;
			$open = 0;
			for($i=0;$i < $max_grps; $i++){
				$access = $grp_info[$i]["ACCESS"];
				$max = count($access);
				for($index=0;$index<$max;$index++){
					if ((substr($access[$index],0,strlen($this->module_command))==$this->module_command) || ($access[$index]=="ALL")){
						$open=1;
					}
				}
			}
			if ($open==1){
				$sql    = "
					select user_status, count(*) as total from user_info 
						left outer join contact_data on contact_data.contact_user = user_identifier 
					where user_client=$this->client_identifier 
						group by user_status 
					order by user_identifier desc
				";
//				print "<li>".__FILE__."@".__LINE__."<p>$sql</p></li>";
				$result = $this->db->query($sql);
				$out="<grouped label=\"User Information\">";
				if ($this->db->num_rows($result)>0){
					$counter=0;
					while (($r=$this->db->fetch_array($result)) && ($counter<$this->page_size)){
					$status_label="";
						$status = $this->check_parameters($r,"user_status");
						if ($status=="0"){
							$status_label = "Total Blocked Users (".$r["total"].")";
						}
						if ($status=="1"){
							$status_label = "Total Unconfirmed Users (".$r["total"].")";
						}
						if ($status=="2"){
							$status_label = "Total Confirmed Users (".$r["total"].")";
						}
						$out .= "<title identifier=\"$status\"><![CDATA[".$status_label."]]></title>";
						$counter++;
					}
					$out .= "<commands><cmd label=\"List\">USERS_LIST</cmd></commands>";
				}else{
					$out .= "<text><![CDATA[".LOCALE_SORRY_NO_USERS."]]></text>";
				}
				$out .= "</grouped>";
				return "<module name=\"users\" label=\"".MANAGEMENT_USER."\" display=\"my_workspace\"><cmd label=\"List All\">USERS_LIST</cmd>".$out."</module>";
//<cmd label=\"".ADD_NEW."\">USERS_ADD</cmd>"
			}else{
				return "";
			}
		} else {
			return "";
		}
	}
	
	/**
	* SPECIAL PAGES
	*
	* Each special page will call a specific function as defined here
	*/
	var $specialPages			 	= array(
		array("-login.php"							,"USERS_SHOW_LOGIN"							,"HIDDEN",	"Login"),
		array("-forgot-username.php"				,"USERS_SHOW_GET_USERNAME_FORM"				,"HIDDEN",	"Forgot Username"),
		array("-forgot-password.php"				,"USERS_SHOW_GET_PWD_FORM"					,"HIDDEN",	"Forgotten Password"),
		array("-logout.php"							,"ENGINE_LOGOUT"							,"HIDDEN",	"Logout"),
		array("-join-now.php"						,"USERS_SHOW_REGISTER"						,"VISIBLE",	"Join Now"),
		array("-profile.php"						,"USERS_SHOW_PROFILE_FORM"					,"VISIBLE",	"Profile")
	);
	
	var $override_forms = array(
		array("-join-now.php"						,"USERS_SHOW_REGISTER"						,"VISIBLE",	"Join Now"),
		array("-profile.php"						,"USERS_SHOW_PROFILE_FORM"					,"VISIBLE",	"Profile")
	);

	/**
	* function produces abstract structure of modules db structure
	*
    * used to generate the table structure required abstract function that passes an abstract
	* representation of the desired table structure to the proper database module which will
	* interpet the abstract and convert it into a valid SQL Create table structure.
	*
	* @return Array list of abstract table definitions for this module
	*/
	function create_table(){
		$tables = array();
		/**
		* Table structure for table 'user_info'
		*/
		
		$fields = array(
			array("user_identifier"			,"unsigned integer"	,"NOT NULL"	,"auto_increment", "key"),
			array("user_login_name"			,"varchar(20)"		,"NOT NULL"	,"default ''"),
			array("user_login_pwd"			,"varchar(40)"		,"NOT NULL"	,"default ''"),
			array("user_creation_date"		,"datetime"			,"" 		,"default NULL"),
			array("user_date_grace"			,"datetime"			,"" 		,"default NULL"),
			array("user_date_review"		,"datetime"			,"" 		,"default NULL"),
			array("user_date_expires"		,"datetime"			,"" 		,"default NULL"),
			array("user_group"				,"unsigned integer"	,"NOT NULL"	,"default '0'"),
			array("user_status"				,"unsigned integer"	,"NOT NULL"	,"default '1'"),
			array("user_client"				,"unsigned integer"	,"NOT NULL"	,"default '0'"),
			array("user_uid"				,"varchar(6)"		,""			,"default ''")
		);
		$primary ="user_identifier";
		$tables[count($tables)] = array("user_info", $fields, $primary);
		/**
		* Table data for table 'user_info'
		*/
		$now = date("d/m/Y H:i:s");
		//$this->db->query("INSERT INTO user_info (user_login_name, user_login_pwd, user_creation_date, user_group, user_status, user_client) VALUES('admin', '6f5393979d674de36c433b47b7d8908e', '$now', '2', '2', '1');");
		/**
		* Table structure for table 'user_status'
		*/
		$fields = array(
		array("user_status_identifier"	,"unsigned integer"	,"NOT NULL"	,"auto_increment"),
		array("user_status_label"		,"varchar(255)"		,"NOT NULL"	,"default ''")
		);
		$primary="user_status_identifier";
		/**
		* Table data for table 'user_status'
		*/
		$data = array(
			'INSERT INTO user_status (user_status_label) VALUES ("LOCALE_USER_NOT_CONFIRMED");',
			'INSERT INTO user_status (user_status_label) VALUES ("LOCALE_USER_CONFIRMED");',
			'INSERT INTO user_status (user_status_label) VALUES ("LOCALE_USER_BLOCKED");'
		);
		$tables[count($tables)] = array("user_status", $fields, $primary, $data);
		/**
		* Table structure for table 'user_management_access'
		*/
		$fields = array(
		array("user_identifier"		,"unsigned integer"	,"NOT NULL"	,"default ''"),
		array("menu_identifier"		,"unsigned integer"	,"NOT NULL"	,"default ''")
		);
		$primary="";
		$tables[count($tables)] = array("relate_user_menu", $fields, $primary);
		/**
		* Table structure for table 'user_extended_functionality' 								  -
		*/
		$fields = array(
			array("tag_identifier"		,"unsigned integer"	,"NOT NULL"	,"auto_increment"),
			array("user_identifier"		,"unsigned integer"	,"NOT NULL"	,"default ''"),
			array("client_identifier"	,"unsigned integer"	,"NOT NULL"	,"default ''"),
			array("function_tag"		,"varchar(30)"		,"NOT NULL"	,"default ''"),
			array("function_value"		,"varchar(30)"		,""			,"default ''")
		);
		$primary="tag_identifier";
		$tables[count($tables)] = array("user_admin_functions", $fields, $primary);
		return $tables;
	}

}
?>